package com.victualler.core.config.permission.service.impl;

import com.victualler.core.base.service.impl.BaseServiceImpl;
import com.victualler.core.config.permission.entity.PermissionInfoDao;
import com.victualler.core.config.permission.entity.RoleInfoDao;
import com.victualler.core.config.permission.repository.PermissionInfoQueryRepository;
import com.victualler.core.config.permission.repository.PermissionInfoRepository;
import com.victualler.core.config.permission.service.PermissionInfoService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: Guoshichang
 * @Date: Create in 17:03 2018/4/5
 * @Discription:  Dict字典类型对应的服务层
 */
@Service
public class PermissionInfoServiceImpl extends BaseServiceImpl<PermissionInfoDao,PermissionInfoRepository,PermissionInfoQueryRepository> implements PermissionInfoService {
    /**
     * @author Guoshichang
     * @since 19:06 on 2018/7/6.
     * @param roleInfoList
     * @Function 根据角色列表获取权限列表
     */
    @Override
    public List<PermissionInfoDao> getPermissionInfoByRoleId(List<RoleInfoDao> roleInfoList) {
        List<Long> ids = new ArrayList<>();
        roleInfoList.forEach(item->{
            ids.add(item.getId());
        });
        return this.baseQueryRepository.getPermissionInfoByRoleId(ids);
    }

    /**
     * @author Guoshichang
     * @since 16:30 on 2018/8/28.
     * @param name 权限名称
     * @return List
     * @Function 根据权限名称模糊查询
     */
    public List<PermissionInfoDao> getByName(String name) {
        return this.baseRepository.findLikeName("%"+name+"%");
    }

    /**
     * @author Guoshichang
     * @since 21:12 on 2018/9/9.
     * @param roleId 双
     * @return List
     * @Function
     */
    public List<PermissionInfoDao> getByRoleId(Long roleId) {
        List<Long> ids = new ArrayList<>();
        ids.add(roleId);
        return this.baseQueryRepository.getPermissionInfoByRoleId(ids);
    }

    /**
     * @author Guoshichang
     * @since 21:12 on 2018/9/9.
     * @param roleId 双
     * @return List
     * @Function
     */
    public List<PermissionInfoDao> notInByRoleId(Long roleId)  {
        return this.baseQueryRepository.notInByRoleId(roleId);
    }
}
